﻿using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using Microsoft.AnalysisServices;

public partial class StoredProcedures
{
    /// <summary>
    /// Check to see if AS is running on a server
    /// </summary>
    /// <returns>int 0 if succesful, -1 if error</returns>
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static int CheckServerAvailability(string olapServer)
    {
        try
        {
            using (Server svr = new Server())
            {
                //Connect to the server
                svr.Connect(olapServer);

                //Disconnect from the server
                svr.Disconnect();

            }
            return 0;

        }
        catch
        {
            //Return fail
            return -1;
        }

    }

}